#!/bin/bash

echo "Testing ROS2 Video Detection Camera Package..."

# 检查ROS2环境
if [ -z "$ROS_DISTRO" ]; then
    echo "Error: ROS2 environment not found. Please source ROS2 setup file first."
    echo "Example: source /opt/ros/humble/setup.bash"
    exit 1
fi

echo "ROS2 Distribution: $ROS_DISTRO"

# 检查摄像头设备
echo "Checking camera devices..."
ls -l /dev/video* 2>/dev/null || echo "No video devices found"

# 检查摄像头权限
echo "Checking camera permissions..."
groups $USER | grep -q video && echo "User has video group access" || echo "User does not have video group access"

# 测试OpenCV摄像头访问
echo "Testing OpenCV camera access..."
python3 -c "
import cv2
cap = cv2.VideoCapture(0)
if cap.isOpened():
    print('Camera 0 is accessible')
    ret, frame = cap.read()
    if ret:
        print(f'Frame captured: {frame.shape}')
    else:
        print('Failed to capture frame')
    cap.release()
else:
    print('Camera 0 is not accessible')
"

echo ""
echo "Test completed!"
echo ""
echo "To run the full package:"
echo "  ros2 launch video_det_camera camera_launch.py"
